package com.hyh.prize.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hyh.prize.entity.Dict;
import com.hyh.prize.entity.TabSaleplanGiftcode;
import com.hyh.prize.service.DictSerive;
import com.hyh.prize.service.GgkStockService;
import com.hyh.prize.service.GiftService;
import com.hyh.prize.vo.GgkConfig;
import com.hyh.prize.vo.LevelAndNumver;
import com.hyh.prize.vo.Yyt;
import com.lww.springcloudapi.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.eclipse.jetty.util.StringUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/admin/ggkConfig/")
@Api(tags = "刮刮卡配置管理")
public class GgkConfigController {

    @Resource
    private DictSerive dictSerive;
    @Resource
    private GgkStockService ggkStockService;
    @Resource
    private GiftService giftService;

    @GetMapping("get/getAddressYyt/{id}")
    @ApiOperation("获取地区下的营业厅")
    public Result getAddressYyt(@PathVariable long id){
        List<Yyt> list = dictSerive.getYyt(id);
        return Result.ok(list);
    }

    @GetMapping("get/getYytName/{code}")
    @ApiOperation("获取营业厅信息")
    public Result getYytName(@PathVariable long code){
        QueryWrapper<Dict> queryWrapper=new QueryWrapper<Dict>();
        queryWrapper.eq("code",code);
        Dict one = dictSerive.getOne(queryWrapper);
        Yyt yyt = dictSerive.getYyt(one);
        return Result.ok(yyt);
    }

    @GetMapping("info/{code}")
    @ApiOperation("获取营业厅奖品配置信息")
    public Result getGgkConfig(@PathVariable String code){
        List<LevelAndNumver> leveInfo = dictSerive.getLeveInfo(code);
        return Result.ok(leveInfo);
    }


    @PostMapping("save")
    @ApiOperation("更新营业厅奖品配置信息")
    public Result updateGgkConfig(@RequestBody List<GgkConfig> list){
        list.stream().forEach(i ->{
            System.out.println(i);
        });
        System.out.println(list);
        boolean b = ggkStockService.updateAll(list);
        if(b){
            return Result.ok();
        }
        return Result.fail();
    }

    @PostMapping("getLpList")
    @ApiOperation("根据等级获取当前等级的所有礼品")
    public Result getLpList(String id,String codeType,String yytId){
        System.out.println("礼品类型："+codeType);
        List list=   ggkStockService.lpByLevelId(id,codeType,yytId);
        return Result.ok(list);
    }

}
